<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分享二维码</title>
    <link href="../css/style.css" rel="stylesheet" type="text/css">
    <link href="../css/base.css" rel="stylesheet" type="text/css">

    <script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../js/paramsTool.js"></script>

</head>
<style>

</style>
<script type="text/javascript">
    var host = window.location.origin;

    if(host == 'http://weblogin.178dn.net') host = 'http://tempa.178dn.net';

    var uid = getCookie('sid');
    var openid = getCookie('wxopenid');
    if(!uid || !openid){
        getWxCode();
        uid = getCookie('sid');
        openid = getCookie('wxopenid');
    }

    var height = window.innerHeight - 50;
    var imgPath = '../qrcode/' + uid + '.png';
    $(document).ready(function() {
        $('#img').attr('src',imgPath).css({width:'100%',height:height,position:'fixed'});
        $('#sharePage').click(function () {
            location.href = host+'/view/shareCode.html?referee='+openid;
        })
    });
    function createCode(){
        $.ajax({
            url: host+ "/createQR",
            type: "get",
            dataType:'json',
            headers: {"content-type":"application/json","sid":uid,'openid':openid},
            success:function(data){
                if(data.code){
                    alert(data.info);
                }else {
                    $("#img").remove();
                    var canvas = $("<canvas id='canvas'></canvas>").appendTo('body');
                    canvas =document.getElementById('canvas');
                    console.log('canvas:',canvas);
                    var ctx = canvas.getContext("2d");
                    canvas.width = window.innerWidth;
                    canvas.height = height;
                    var img =new Image();
                    img.src=imgPath;
                    img.onload = function () {              //图片加载完再操作,不然不会显示,再去写字,文字也是,要在图片后面写,不然会被挡住
                        ctx.drawImage(img,0,0,canvas.width,canvas.height);
                        ctx.fillStyle= "#FFF100"; //文字颜色
                        ctx.font="22px Georgia";
//                    ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
                        // 将阴影向右移动15px，向上移动10px
                        ctx.shadowOffsetX = 15;
                        ctx.shadowOffsetY = -10;
                        // 轻微模糊阴影
                        ctx.shadowBlur = 2;
                        ctx.fillText("ID:"+uid,10,25);
                        ctx.restore();
                    }
                }
            },
            error:function() {
                 alert('生成推荐码失败,请重试!');
            }

        })

    }

</script>
<body>
<img id="img" onerror='createCode()'>
<!--底部导航-->
<div class="spring_bar">
    <a href="minWheel.html">
        <dl class="list">
            <dt class=""><img src="../image/ctb1.png" /></dt>
            <dd>幸运转盘</dd>
        </dl>
    </a>
    <a id="sharePage">
        <dl class="list">
            <dt><img src="../image/ctb2on.png" /></dt>
            <dd class="tbon">推广二维码</dd>
        </dl>
    </a><a href="postCash.html">
    <dl class="list">
        <dt><img src="../image/ctbm.png" /></dt>
        <dd></dd>
    </dl>
</a><a href="recharge.html">
    <dl class="list">
        <dt>
            <img src="../image/ctb3.png" />
        </dt>
        <dd> 充值中心 </dd>
    </dl> </a>
    <a href="me.html">
        <dl class="list">
            <dt><img src="../image/ctb4.png" /></dt>
            <dd>个人中心</dd>
        </dl>
    </a>
</div>
<!--底部导航end-->
</body>
</html>